<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');

include(JPATH_ROOT.DS."administrator".DS."components".DS."com_surveys".DS."left.php");

$document =& JFactory::getDocument();
$document->addStyleSheet("components/com_surveys/css/survey.css");

$app = JFactory::getApplication('administrator');
$limistart = $app->getUserStateFromRequest('com_surveys.responses'.'.list.start', 'limitstart');
$limit = $app->getUserStateFromRequest('com_surveys.responses'.'.list.limit', 'limit');

$search = JRequest::getVar("search", "");
$field = JRequest::getVar("field", "name");
?>

<form action="index.php" method="post" name="adminForm" id="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminheading">
		<tr>
			<td ><h2 style="color:#669900"><img src="<?php echo JUri::base();?>components/com_surveys/images/icons/surveys.png" width="48" height="48" align="middle" /><?php echo JText::_("COM_SURVEYS_RESPONSES_MANAGER"); ?></h2></td>
			<td align="right" valign="bottom"> 
				<table align="right">					
					<tr>
						<td nowrap valign="bottom">
							<table align="right">
								<td valign="middle" align="right">
									<?php echo JText::_("COM_SURVEYS_FILTER");?>:
								</td>
								<td>
									<select name="field">
										<option value="name" <?php if($field == "name"){echo ' selected="selected" ';} ?> ><?php echo JText::_("COM_SURVEYS_NAME"); ?></option>
										<option value="username" <?php if($field == "username"){echo ' selected="selected" ';} ?>><?php echo JText::_("COM_SURVEYS_USERNAME"); ?></option>
										<option value="email" <?php if($field == "email"){echo ' selected="selected" ';} ?>><?php echo JText::_("COM_SURVEYS_EMAIL"); ?></option>
										<option value="ip" <?php if($field == "ip"){echo ' selected="selected" ';} ?>><?php echo JText::_("COM_SURVEYS_IP"); ?></option>
									</select>
								</td>
								<td valign="middle" align="right">
									<input type="text" name="search" value="<?php echo $search; ?>" class="text_area" onChange="document.adminForm.submit();" />
								</td>								
								<td valign="middle">
									<input type="submit" name="submit_btn" value="<?php echo JText::_("COM_SURVEYS_GO");?>" />
								</td>
							</table>
						</td>
					</tr>				
				</table>
			</td>			
		</tr>		
	</table>
	
	<table cellpadding="9" cellspacing="0" border="0" width="100%" class="adminlist">		
		<tr>
			<th width="5%" align="center">#</th>			
			<th width="5%" align="center"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" /></th>
			<th width="15%" align="left"><?php echo JText::_("COM_SURVEYS_NAME"); ?></th>
			<th width="20%" align="left"><?php echo JText::_("COM_SURVEYS_USERNAME"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_EMAIL"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_IP"); ?></th>
			<th width="20%" align="center"><?php echo JText::_("COM_SURVEYS_DATE_TIME"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_PUBLISHED"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_VIEW_RESPONSE"); ?></th>		
		</tr>
		<?php
		$k = $limistart+1;
		$j = 0;
		if($this->items != NULL && is_array($this->items) && count($this->items)>0)
		for($i=0; $i<count($this->items); $i++) {						
			$item = $this->items[$i];
		?>
			<tr class="<?php echo "row".$j; ?>">
				<td align="center"><?php echo $k; ?></td>
				<td align="center"><?php echo JHtml::_('grid.id', $i, $item->id); ?></td>
				<td align="left">
				<?php 
					if($item->name != ""){
						echo $item->name;
					}
					else{
						echo "N/A";
					}
				?>					
				</td>
				<td align="left">
				<?php 
					if($item->username != ""){
						echo $item->username;
					}
					else{
						echo "N/A";
					}
				?>					
				</td>
				<td align="left">
				<?php 
					if($item->email != ""){
						echo $item->email;
					}
					else{
						echo "N/A";
					}
				?>					
				</td>
				<td><?php echo $item->ip; ?></td>
				<td align="center"><?php echo $item->played_time; ?></td>
				<td align="center"><?php echo JHTML::_('grid.published', $item->published, $i); ?></td>
				<td align="center"><a href="<?php echo JURI::root()."administrator/index.php?option=com_surveys&controller=statistics&s_id=".JRequest::getVar("id")."&r_id=".$item->id; ?>"><?php echo JText::_("COM_SURVEYS_SURVEY_VIEW"); ?></a></td>
			</tr>
		<?php
			$k ++;
			$j = 1-$j;			
		}	
		?>
		<tfoot>
			<tr>
				<td colspan="9">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
	</table>
	
	<input type="hidden" name="id" value="<?php echo JRequest::getVar("id"); ?>" />	
	<input type="hidden" name="option" value="com_surveys" />
	<input type="hidden" name="controller" value="responses" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<?php echo JHtml::_('form.token'); ?>
</form>


</td></tr></table>
<p><center><?php echo JText::_("COM_IJOOMLA_SURVEYS_POWERED_BY") ; ?>&nbsp;<a href='http://www.ijoomla.com' target='_blank'><?php echo JText::_("COM_SURVEYS_SURVEY"); ?></a></center></p>	